/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.dao;

import br.com.deployment.daogenerico.DaoGenerico;
import br.com.deployment.entidade.empresa.Cartorio;
import br.com.deployment.interfaces.CartorioDaoIn;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author luciano
 */
@Stateless
@LocalBean
public class CartorioDao extends DaoGenerico<Cartorio> implements CartorioDaoIn{

    public CartorioDao() {
        super(Cartorio.class);
    }
    
    public Boolean exist(Cartorio cartorio) {
        if (getEm().contains(cartorio)) {
            return true;
        } else {
            return false;
        }
    }
    
     public List<Cartorio> findCartorio(Cartorio cartorio) {
        List<Cartorio> listCartorio = new ArrayList<Cartorio>();
        if (cartorio != null) {
            String sql = "select c from Cartorio c";

            if (cartorio.getNome() != null && cartorio.getNome().length() > 0) {
                sql += " where c.nome like ?1 ";
            }
    
            Query query = getEm().createQuery(sql);
            if (cartorio.getNome() != null && cartorio.getNome().length() > 0) {
                query.setParameter("1", "%" + cartorio.getNome() + "%");
            }
             
            listCartorio = query.getResultList();
            return listCartorio;
        }
        return null;
    }
   
    
}
